package com.example.springbootdemo.controller;

import com.example.springbootdemo.ojop.Poi;
import com.example.springbootdemo.repository.PoiRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/poi")
@CacheConfig(cacheNames = "poi_cache")
@Api(tags = "POI接口")
public class PoiController {

    @Autowired
    private PoiRepository poiRepository;

    @GetMapping("/findAll")
    @Cacheable
    @ApiOperation(value="查询poi", notes = "查询所有的poi")
    public List<Poi> list(){
        return poiRepository.findAll();
    }

    @GetMapping("/findOne")
    @ApiOperation(value = "查询poi", notes = "根据名称查询poi")
    @ApiImplicitParam(paramType = "path", name = "name", value = "poi名称", required = true)
    public Poi one(@RequestParam String name){
        return poiRepository.findByName(name);
    }
}
